<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script src="js/axios.js"></script>
    <script>
        // 请求发送时在请求头中添加mytoken属性
        // 
        axios.interceptors.request.use(function(config) {
            console.log(config);

            if (config.url == 'http://127.0.0.1:3000/adata') {
                config.headers['mytoken'] = 'hello'
            }
            return config
        })

        // 请求响应时 对数据data进行加工处理
        axios.interceptors.response.use(function(res) {
            console.log(res);
            return res.data
        })

        axios.get('http://127.0.0.1:3000/adata').then(function(res) {
            console.log(res);

        })
    </script>


</body>

</html>